This script takes the clean QV data and calculates the parameters of the model - using MLE - assuming a two-step process starting with choosing a vote class and then casting the vote(s) on the most preferred issue(s). The thresholds determining the choice of vote class along with the probabilities of making a mistake at either step of the process are estimated from the MTurk sample. Denoting by v_k the voter’s kth highest value assigned to a proposal, we conjecture that behavior can be summarized by five parameters {rho, gamma, csi*, epsilon, mu}. Now, assume we have a candidate vector {rho, gamma, csi, epsilon, mu}. 

*Note: In prior drafts, version of code, and emails we have used xi,csi, and eta interchangeably despite referring to the same parameter.  

First, in order to determine the optimal choice of vote class, we let the optimal (i.e., correct) choice be determined by the thresholds:
- If v(4)/v(3) > rho, then R;
- If v(4)/v(3) = rho, then R or Y;
- If v(4)/v(3) < rho, but v(3)/v(2) > gamma, then Y;
- If v(4)/v(3) < rho, but v(3)/v(2) = gamma, then Y or G;
- If v(4)/v(3) < rho, v(3)/v(2) < gamma, but v(2)/v(1) > csi, then G;
- If v(4)/v(3) < rho, v(3)/v(2) < gamma, but v(2)/v(1) = csi, then G or B;
- If v(4)/v(3) < rho, v(3)/v(2) < gamma, and v(2)/v(1) < csi, then B;
If the individual made the right choice then he/she is assigned a likelihood value of epsilon and otherwise, if the agent made a mistake when choosing the vote class, then the likelihood assigned is epsilon/3.

Second, given the observed vote class, with probability 1-mu all votes are cast monotonically, i.e., on the highest intensity initiatives, and otherwise the votes are cast non-monotonically. In order to estimate this, we tabulated all the ways in which the vote(s) could be cast and determined how many of these would be considered weakly monotone and how many would not. Thus, if the subject failed to cast the vote(s) monotonically he/she was assigned a probability of mu/#nonMonotone and otherwise a probability of (1-mu)/#Monotone. 

Given the likelihood function for each agent, we took the sum of the negative log likelihoods and used this as our loss function to be minimized. In order to find the minima we used the "dfoptim" R-package which uses Nelder-Mead optimization algorithms (combined with arctan-bounds to enforce box-constraints) to minimize this function. Since the loss function itself had multiple local minima, we used a simulated annealing algorithm in order to find the best starting vector for the original data. The same starting point is used for the bootstrapped data. 

